package com.coderman.youpinshop.stock.service.impl;

import com.coderman.youpinshop.stock.bo.*;
import com.coderman.youpinshop.stock.cache.StockCacheService;
import com.coderman.youpinshop.stock.dataobject.StockDO;
import com.coderman.youpinshop.stock.enums.StockOperationEnum;
import com.coderman.youpinshop.stock.mapper.StockMapper;
import com.coderman.youpinshop.stock.mapper.StockRecordMapper;
import com.coderman.youpinshop.stock.mq.StockMqSerivce;
import com.coderman.youpinshop.stock.service.StockService;
import com.coderman.youpinshop.stock.support.SpringApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.xml.ws.soap.Addressing;

/**
 * Description:涨血模型的业务逻辑
 * date: 2022/1/15
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Component(value = "highBloodStockService")
public class HighBloodStockServiceImpl implements StockService {

    @Autowired
    private StockMapper stockMapper;

    @Autowired
    private StockRecordMapper stockRecordMapper;

    @Autowired
    private StockCacheService cacheService;

    @Autowired
    private StockMqSerivce stockMqSerivce;


    @Autowired
    private StockHighBloodV3BO stockHighBloodV3BO;




    @Override
    public boolean deduct(String stockCode, Integer deductCount) {
        //在涨血模型下整个扣库存的逻辑都被放到了StockHighBloodBO里面了，所以很明显的我们可以看到
        //为了让涨血模型执行业务逻辑我们不得不让他去关联整个他所依赖的业务对象
        //因为这里的demo 用的是spring框架，所以会显得尤其别扭，当然这里有可以将这些对象通过SpringContextUtils来获取
        //这样的话整个逻辑看上去像下面的版本
        //假设这是涨血模型的第一个版本
        /*StockHighBloodBO stockHighBloodBO = StockHighBloodBO.getInstance(stockCode)
                .stockMapper(stockMapper)
                .cacheService(cacheService)
                .stockMqService(stockMqSerivce);
        return stockHighBloodBO.exeDeduct(deductCount);*/




        //假设这是涨血模型的第二个版本
      /*  StockHighBloodV2BO stockHighBloodV2BO = StockHighBloodV2BO.getInstance(stockCode);
        return stockHighBloodV2BO.exeDeduct(deductCount);*/

        //假设这是涨血模型的第三个版本
        stockHighBloodV3BO.setStockCode(stockCode);
        return stockHighBloodV3BO.exeDeduct(deductCount);

    }
}
